package com.megastudyletsthi;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.hocmai.user.account.UserAccountActivity;
import com.hocmai.user.toprank.UserTopRankActivity;

public class HocmaiMainWorkActivity extends Activity{
 
	WebView webView;
	Button userAccount, userTopRank;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_layout);
		userAccount = (Button) findViewById(R.id.btn_account);
		userTopRank = (Button) findViewById(R.id.btn_setting_account);
		webView = (WebView) findViewById(R.id.webViewContent);

		webView.setWebViewClient(new myWebClient());
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl("http://vozforums.com/");

		userAccount.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(HocmaiMainWorkActivity.this,
						UserAccountActivity.class);
				startActivity(intent);
			}
		});

		userTopRank.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(HocmaiMainWorkActivity.this,
						UserTopRankActivity.class);
				startActivity(intent);
			}
		});
	}
	// ///////////////////////////////////////////////////////////
	public class myWebClient extends WebViewClient {
		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			super.onPageStarted(view, url, favicon);
		}

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}
	// ///////////////////////////////////////////////////////////
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
			webView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
